QuickOPC User's Guide and Reference
Examples - OPC Unified Architecture - Read a single attribute of a single node
View with Navigation Tools

.NET 

// This example shows how to read and display data of an attribute (value, timestamps, and status code).

using System;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.OperationModel;

namespace UADocExamples._EasyUAClient
{
    partial class Read
    {
        public static void Main1()
        {
            UAEndpointDescriptor endpointDescriptor =
                "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
            // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
            // or "https://opcua.demo-this.com:51212/UA/SampleServer/"

            // Instantiate the client object.
            var client = new EasyUAClient();

            // Obtain attribute data. By default, the Value attribute of a node will be read.
            UAAttributeData attributeData;
            try
            {
                attributeData = client.Read(endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853");
            }
            catch (UAException uaException)
            {
                Console.WriteLine($"*** Failure: {uaException.GetBaseException().Message}");
                return;
            }

            // Display results
            Console.WriteLine($"Value: {attributeData.Value}");
            Console.WriteLine($"ServerTimestamp: {attributeData.ServerTimestamp}");
            Console.WriteLine($"SourceTimestamp: {attributeData.SourceTimestamp}");
            Console.WriteLine($"StatusCode: {attributeData.StatusCode}");

            // Example output:
            //
            //Value: -2.230064E-31
            //ServerTimestamp: 11/6/2011 1:34:30 PM
            //SourceTimestamp: 11/6/2011 1:34:30 PM
            //StatusCode: Good
        }
    }
}

COM 

// This example shows how to read and display data of an attribute (value, timestamps, and status code).

#include "stdafx.h"    // Includes "QuickOpc.h", and other commonly used files
#include "Read.h"

namespace _EasyUAClient
{
    void Read::Main()
    {
        // Initialize the COM library
        CoInitializeEx(NULL, COINIT_MULTITHREADED);
        {
            // Instantiate the client object
            _EasyUAClientPtr ClientPtr(__uuidof(EasyUAClient));

            // Obtain attribute data. By default, the Value attribute of a node will be read.
            _UAAttributeDataPtr AttributeDataPtr = ClientPtr->Read(
                //L"http://opcua.demo-this.com:51211/UA/SampleServer", 
                L"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer",
                L"nsu=http://test.org/UA/Data/ ;i=10853");
    
            // Display results
            _variant_t vString;
            vString.ChangeType(VT_BSTR, &AttributeDataPtr->Value);
            _tprintf(_T("Value: %s\n"), (LPCTSTR)CW2CT((_bstr_t)vString));
            vString.ChangeType(VT_BSTR, &_variant_t(AttributeDataPtr->ServerTimestamp, VT_DATE));
            _tprintf(_T("ServerTimestamp: %s\n"), (LPCTSTR)CW2CT((_bstr_t)vString));
            vString.ChangeType(VT_BSTR, &_variant_t(AttributeDataPtr->SourceTimestamp, VT_DATE));
            _tprintf(_T("SourceTimestamp: %s\n"), (LPCTSTR)CW2CT((_bstr_t)vString));
            _tprintf(_T("StatusCode: %s\n"), (LPCTSTR)CW2CT(AttributeDataPtr->StatusCode->ToString));

            // Example output:
            //
            //Value: -2.230064E-31
            //ServerTimestamp: 11/6/2011 1:34:30 PM
            //SourceTimestamp: 11/6/2011 1:34:30 PM
            //StatusCode: Good

        }
         // Release all interface pointers BEFORE calling CoUninitialize()
        CoUninitialize();
    }
}

Tools

:: This example shows how to read and display data of an attribute (value, timestamps, and status code).

:: Invoke the OPC UA client.
uaClient

:: Obtain attribute data and display results. By default, the Value attribute of a node will be read.
read opc.tcp://opcua.demo-this.com:51210/UA/SampleServer "nsu=http://test.org/UA/Data/ ;i=10853"

 

See Also

Conceptual

Examples - OPC Data Access

Examples - OPC UA Interaction

Examples - OPC UA Layered Extensions